package com.llgz.hotelmanageapi.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.llgz.hotelmanageapi.common.CommonResult;
import com.llgz.hotelmanageapi.pojo.DO.*;
import com.llgz.hotelmanageapi.pojo.DO.OrderInfo;
import com.llgz.hotelmanageapi.pojo.DO.OrderInfo;
import com.llgz.hotelmanageapi.service.impl.OrderInfoServiceImpl;
import com.llgz.hotelmanageapi.service.impl.OrderInfoServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订房信息表 前端控制器
 * </p>
 *
 * @author Bernie_fang
 * @since 2021-07-19
 */
@RestController
@RequestMapping("/orderInfo")
@RequiresRoles(value = {"root", "admin", "manager", "reception"}, logical = Logical.OR)
public class OrderInfoController {
    @Autowired
    OrderInfoServiceImpl orderInfoService;

    /**
     * @MethodName addOrderInfo
     * @Params * @param OrderInfo
     * @Description 添加
     * @Return CommonResult
     */
    @PostMapping("/addOrderInfo")
    @ApiOperation(value = "添加", response = CommonResult.class, httpMethod = "POST")
    public CommonResult addOrderInfo(@RequestBody OrderInfo orderInfo){
        boolean save = orderInfoService.save(orderInfo);
        return CommonResult.successResponse(save);
    }
    /**
     * @MethodName getOrderInfoList
     * @Params * @param OrderInfo
     * @Description 查找全部
     * @Return CommonResult
     */
    @GetMapping("/getOrderInfoList")
    @ApiOperation(value = "查找", response = CommonResult.class, httpMethod = "GET")
    public CommonResult getOrderInfoList(@RequestParam String query,@RequestParam Integer pageNum,@RequestParam Integer pageCount){
        QueryWrapper<OrderInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("modified_time");
        if (query != null && !query.isEmpty()){
            queryWrapper.like("",query);
        }
        IPage<OrderInfo> page = orderInfoService.page(new Page<>(pageNum, pageCount), queryWrapper);
        return CommonResult.successResponse(page);
    }
    @GetMapping("/getOrderInfoById")
    @ApiOperation(value = "查找(Id)", response = CommonResult.class, httpMethod = "GET")
    public CommonResult getOrderInfoById(@RequestParam String id){
        OrderInfo category = orderInfoService.getOne(new QueryWrapper<OrderInfo>().eq("id", id));
        return CommonResult.successResponse(category);
    }
    /**
     * @MethodName updateOrderInfo
     * @Params * @param OrderInfo
     * @Description 更新
     * @Return CommonResult
     */
    @PostMapping("/updateOrderInfo")
    @ApiOperation(value = "更新", response = CommonResult.class, httpMethod = "POST")
    public CommonResult updateOrderInfo (@RequestBody OrderInfo orderInfo){
        boolean b = orderInfoService.updateById(orderInfo);
        return CommonResult.successResponse(b);
    }
//    /**
//     * @MethodName deleteOrderInfo
//     * @Params * @param OrderInfo
//     * @Description 删除
//     * @Return CommonResult
//     */
//    @PostMapping("/deleteOrderInfo")
//    @ApiOperation(value = "删除", response = CommonResult.class, httpMethod = "POST")
//    public CommonResult deleteOrderInfo (@RequestParam String id){
//        boolean b = orderInfoService.removeById(id);
//        return CommonResult.successResponse(b);
//    }
    /**
     * @MethodName deleteOrderInfo
     * @Params * @param OrderInfo
     * @Description 删除（多选）
     * @Return CommonResult
     */
    @PostMapping("/deleteOrderInfo")
    @ApiOperation(value = "删除（多选）", response = CommonResult.class, httpMethod = "POST")
    public CommonResult deleteOrderInfo (@RequestBody List<String> ids){
        boolean b = orderInfoService.removeByIds(ids);
        return CommonResult.successResponse(b);
    }
}

